package com.guigu.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.pojo.Employee;
import com.guigu.pojo.Msg;
import com.guigu.service.EmployeeService;



@Controller
public class EmployeeController extends ExtendsClass {
	@Resource
	EmployeeService employeeService;
	
	@RequestMapping(value="emps",method=RequestMethod.GET)
	@ResponseBody
	public  Msg getEmps(@RequestParam(value="pn",defaultValue="1")Integer pn)
	{
		//获取第pn页，10条内容，默认查询总数count
		PageHelper.startPage(pn, 10);
		List<Employee> list= employeeService.getAll();
		PageInfo<Employee> page = new PageInfo<Employee>(list,5);
		//把返回的對象放在一個map容器中
		return Msg.success().add("pageInfo", page);
	}
	
	//测试用的
//	@RequestMapping(value="emps",method=RequestMethod.GET)
//	public  String getEmps(@RequestParam(value="pn",defaultValue="1")Integer pn)
//	{
//		//获取第pn页，10条内容，默认查询总数count
//		PageHelper.startPage(pn, 10);
//		List<Employee> list= employeeService.getAll();
//		PageInfo<Employee> page = new PageInfo<Employee>(list,5);
//		//把返回的對象放在一個map容器中
//		request.setAttribute("pageInfo", page);
//		return "list";
//	}
	//添加员工信息
	@RequestMapping(value="addEmps",method=RequestMethod.POST)
	@ResponseBody
	public  String addEmps(String name,String Email1,String gender,String d_id)
	{
		Integer dId=new Integer(d_id);
		Employee ems=new Employee();
		ems.setEmpName(name);
		ems.setEmail(Email1);
		ems.setGender(gender);
		ems.setdId(dId);
		employeeService.insertEmployee(ems);
		return "success";
		
	}
	
	//添加员工信息
		@RequestMapping(value="delEmps",method=RequestMethod.GET)
		@ResponseBody
		public  String delEmps(String empId)
		{
			Integer eId=new Integer(empId);
			employeeService.delEmployee(eId);
			return "success";
			
		}
	
	
}


